import Vue from "vue";
import VueRouter from "vue-router";

import Home from "../views/home/Home.vue";
import Category from "../views/category/Category.vue";
import Cart from "../views/cart/Cart.vue";
import My from "../views/my/My.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    meta: {
      title: "首页",
    },
    component: Home,
  },
  {
    path: "/category",
    meta: {
      title: "分类",
    },
    component: Category,
  },
  {
    path: "/cart",
    meta: {
      title: "购物车",
    },
    component: Cart,
  },
  {
    path: "/my",
    meta: {
      title: "我的",
    },
    component: My,
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

router.beforeEach((to, from, next) => {
  next();
  document.title = to.matched[0].meta.title;
});

export default router;
